package com.genexususa.eo.bing.data.wsSubclasses;

import com.genexususa.eo.bing.CampaignManagementServiceClasses.AccountAnalyticsType;
import com.genexususa.eo.bing.CampaignManagementServiceClasses.AnalyticsType;
import com.genexususa.eo.bing.data.GxItemException;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

public class GxAccountAnalyticsType extends AccountAnalyticsType {
    private long gxAccountId;

    public GxAccountAnalyticsType(Element element) throws IllegalArgumentException, GxItemException {
        if (element.getElementsByTagName("GxAccountId").getLength() > 0 &&
            element.getElementsByTagName("GxAccountId").item(0).getChildNodes().getLength() > 0 &&
            Long.valueOf(((Node)element.getElementsByTagName("GxAccountId").item(0).getChildNodes().item(0)).getNodeValue()) != 0) {
            this.gxAccountId = Long.valueOf(((Node)element.getElementsByTagName("GxAccountId").item(0).getChildNodes().item(0)).getNodeValue());
        } else {
            throw new GxItemException("Missing external Account id");
        }
        if (element.getElementsByTagName("BingAccountId").getLength() > 0 &&
            element.getElementsByTagName("BingAccountId").item(0).getChildNodes().getLength() > 0 &&
            Long.valueOf(((Node)element.getElementsByTagName("BingAccountId").item(0).getChildNodes().item(0)).getNodeValue()) != 0) {
            this.setAccountId(Long.valueOf(((Node) element.getElementsByTagName("BingAccountId").item(0).getChildNodes().item(0)).getNodeValue()));
        }
        if (element.getElementsByTagName("Type").getLength() > 0 &&
            element.getElementsByTagName("Type").item(0).getChildNodes().getLength() > 0) {
            this.setType(AnalyticsType.fromString(((Node) element.getElementsByTagName("Type").item(0).getChildNodes().item(0)).getNodeValue()));
        }
    }

    public long getGxAccountId() {
        return gxAccountId;
    }

    public void setGxAccountId(long gxAccountId) {
        this.gxAccountId = gxAccountId;
    }
}
